package com.taojie.graduation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.taojie.graduation.domain.Admin;
import com.taojie.graduation.mapper.AdminMapper;
import com.taojie.graduation.service.api.AdminService;
import com.taojie.graduation.utils.Result;
import com.taojie.graduation.utils.ResultCode;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * @ClassName AdminServiceImpl
 * @Description TODO
 * @Author Chole
 * @Date 2020/4/19 16:44
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Resource
    private AdminMapper adminMapper;

    @Override
    public Result findAdmin(Admin admin) {
        if (StringUtils.isEmpty(admin.getName()) || StringUtils.isEmpty(admin.getPassword())){
            return new Result(ResultCode.MOBILEORPASSWORDERROR);
        }
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("name", admin.getName());
        wrapper.eq("password", admin.getPassword());
        Admin admin1 = adminMapper.selectOne(wrapper);
        if (ObjectUtils.isEmpty(admin1)) {
            return new Result(ResultCode.FAIL);
        }
        return new Result(ResultCode.SUCCESS, admin1);
    }
}
